<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Untitled Document</title>
        <style type="text/css">
            <!--
            .style1 {
                color: #20364E;
                font-size: 24px;
                font-weight: bold;
            }
            .style9 {
                font-size: 36px
            }
            body {
                background-color: #A7BFDB;
            }
            -->
        </style>
    </head>

    <body>
        <p align="center"><span class="style1">Cadastro de Funcion&aacute;rio</span></p>
        <%
                    Class.forName("org.postgresql.Driver");
                    Connection con = DriverManager.getConnection("jdbc:postgresql://localhost/ses", "postgres", "postgres");
                    Statement st = con.createStatement();
                    ResultSet rs;

                    if (request.getParameter("acao") == null) {

        %>
        <form id="frmInserirFuncionario" name="frmInserirFuncionario" method="post" action="cadFuncionario.jsp?acao=gravar">
            <table width="978" border="0" align="center">
              <tr>
                <td colspan="6">&nbsp;</td>
              </tr>
              <tr>
                <td width="131">C&oacute;digo.:</td>
<td width="127"><label>
                  <input name="tf_codigo" type="text" id="tf_codigo" value="autom&aacute;tico" size="19" maxlength="15" disabled="disabled"/>
                </label></td>
                <td width="127"><label>Nome Funcion&aacute;rio.:                </label>
                  <label></label></td>
                <td width="255"><input name="tf_nome" type="text" id="tf_nome" size="40" maxlength="40" /></td>
                <td width="73"><label>CPF.:                </label>
                  <label></label></td>
                <td width="239"><input name="tf_cpf" type="text" id="tf_cpf" size="16" maxlength="16" onkeypress="formata_mascara(this,'###.###.###-##'); return Numero(event);" /></td>
              </tr>
              <tr>
                <td width="131">Tipo Logradouro.:</td>
                <td width="127"><label>
                  <select name="lista_tipologradouro" id="lista_tipologradouro">
                    <option></option>
                    <option>Rua</option>
                    <option>Viela</option>
                    <option>Avenida</option>
                    <option>Pra&ccedil;a</option>
                    <option>Rodovia</option>
                    <option>Fazenda</option>
                    <option>Beco</option>
                  </select>
                </label></td>
                <td colspan="4">Logradouro.:
                  <label>
                  <input name="tf_logradouro" type="text" id="tf_logradouro" size="80" maxlength="80" />
                  </label></td>
              </tr>
              <tr>
                <td width="131">N&uacute;mero.:</td>
                <td width="127"><label>
                  <input name="tf_numero" type="text" id="tf_numero" size="18" maxlength="10" />
                  </label>
                <label></label></td>
                <td colspan="4">CEP.:
                  <label></label>                  <input name="tf_cep" type="text" id="tf_cep" size="13" maxlength="12" /></td>
              </tr>
              <tr>
                <td width="131">Tipo Complemento.:</td>
                <td width="127"><label>
                  <select name="lista_tipocomplemento" id="lista_tipocomplemento">
                    <option></option>
                    <option>Em Frente</option>
                    <option>Ao lado</option>
                    <option>Acima</option>
                    <option>Atr&aacute;s</option>
                    <option>Pr&oacute;ximo</option>
                  </select>
                </label></td>
                <td colspan="4">Complemento.:
                  <label></label>                  <input name="tf_complemento" type="text" id="tf_complemento" size="45" maxlength="30" /></td>
              </tr>
              <tr>
                <td width="131">Bairro.:
                  <label></label>
                <label></label></td>
                <td width="127"><input name="tf_bairro" type="text" id="tf_bairro" size="20" maxlength="20" /></td>
                <td width="127">Cidade.:
                <label></label></td>
                <td><input name="tf_cidade" type="text" id="tf_cidade" size="28" maxlength="30" /></td>
                <td width="73">Estado.:
                <label></label></td>
                <td><select name="lista_estado" id="lista_estado">
                  <option></option>
                  <option>AC</option>
                  <option>AL</option>
                  <option>AM</option>
                  <option>AP</option>
                  <option>BA</option>
                  <option>CE</option>
                  <option>DF</option>
                  <option>ES</option>
                  <option>GO</option>
                  <option>MA</option>
                  <option>MG</option>
                  <option>MS</option>
                  <option>MT</option>
                  <option>PA</option>
                  <option>PB</option>
                  <option>PE</option>
                  <option>PI</option>
                  <option>PR</option>
                  <option>RJ</option>
                  <option>RN</option>
                  <option>RO</option>
                  <option>RR</option>
                  <option>RS</option>
                  <option>SC</option>
                  <option>SE</option>
                  <option>SP</option>
                  <option>TO</option>
                </select></td>
              </tr>
              <tr>
                <td width="131">Apelido.:  
                  <label></label>
                <label></label></td>
                <td width="127"><input name="tf_apelido" type="text" id="tf_apelido" size="18" /></td>
                <td width="127">Senha.:
                <label></label></td>
                <td colspan="3"><input name="tf_senha" type="password" id="tf_senha" size="20"/></td>
              </tr>
              <tr>
                <td width="131">Fone Res.:
                  <label></label>
                  <label></label>
                <label></label></td>
                <td width="127"><input name="tf_foneres" type="text" id="tf_foneres" size="17" /></td>
                <td width="127">Fone Cel.:
                <label></label></td>
                <td><input name="tf_fonecel" type="text" id="tf_fonecel" size="16" /></td>
                <td width="73">Fone Fax.:
                <label></label></td>
                <td><input name="tf_fonefax" type="text" id="tf_fonefax" size="16" /></td>
              </tr>
              <tr>
                <td colspan="2">Tipo de Usu&aacute;rio.:
                <label> </label>
                <label>
                <br />
                <input type="radio" name="tipousuario" value="Gerente" id="tipousuario_2" />
Gerente Financeiro</label>
                  <br />
                  <label>
                  <input type="radio" name="tipousuario" value="Agente" id="tipousuario_3" />
Agente Financeiro</label></td>
              <td colspan="4">Administrador.:
                <label>
                <br />
                </label>
                <label></label>
                <label>
                <input type="radio" name="administrador" value="Sim" id="administrador_2" />
Sim</label>
                <label> <br />
                <input type="radio" name="administrador" value="N&atilde;o" id="administrador_3" />
N&atilde;o</label></td>
              </tr>
              
              <tr>
                <td colspan="6">Departamento.:
                  <label>
                  <select name="lista_departamento" id="lista_departamento">
                  <%
			     				String sqldepartamento = "select * from departamento order by nome";
				 				rs = st.executeQuery(sqldepartamento);
				 				while(rs.next())
				 		{ %>
                     			<option><%=rs.getString("nome")%></option> 
                             	<%}
								%>
                  </select>
</label></td>
              </tr>
              <tr>
                <td colspan="6">&nbsp;</td>
              </tr>
              <tr>
                <td colspan="6"><label>
                  <input type="submit" name="gravar" id="gravar" value="Gravar" />
                </label>
                  <label></label>
                  <input type="reset" name="Limpar" id="Limpar" value="Limpar" /></td>
              </tr>
            </table>
            <label></label>
      <p>
                <label></label>
        <label></label>
      </p>
    </form>
        <% } else {
                        String sqlinsertfun = "insert into funcionario (nome, cpf, tipologradouro, logradouro, numero, " +
                                "tipocomplemento, complemento, bairro, cidade, estado, cep, " +
                                "apelido, senha, foneres, fonecel, fonefax, tipousuario, administrador, departamento) " +
                                " VALUES ('" + request.getParameter("tf_nome") +
                                "','" + request.getParameter("tf_cpf") +
                                "','" + request.getParameter("lista_tipologradouro") +
                                "','" + request.getParameter("tf_logradouro") +
                                "','" + request.getParameter("tf_numero") +
                                "','" + request.getParameter("lista_tipocomplemento") +
                                "','" + request.getParameter("tf_complemento") +
                                "','" + request.getParameter("tf_bairro") +
                                "','" + request.getParameter("tf_cidade") +
                                "','" + request.getParameter("lista_estado") +
                                "','" + request.getParameter("tf_cep") +
                                "','" + request.getParameter("tf_apelido") +
                                "','" + request.getParameter("tf_senha") +
                                "','" + request.getParameter("tf_foneres") +
                                "','" + request.getParameter("tf_fonecel") +
                                "','" + request.getParameter("tf_fonefax") +
                                "','" + request.getParameter("tipousuario") +
                                "','" + request.getParameter("administrador") +
                                "','" + request.getParameter("lista_departamento") + "')";

                        st.executeUpdate(sqlinsertfun);
                        response.sendRedirect("cadFuncionario.jsp");
                    }%>
        <p align="center" class="style9">&nbsp;</p>
        <p>&nbsp;</p>
    </body>
</html>